//
//  tklTextViewAlertView.m
//  dongfengTest
//
//  Created by wxt on 2021/3/18.
//

#import "TKLTextViewAlertView.h"

@interface TKLTextViewAlertView ()<UITextViewDelegate>

@property(nonatomic,strong)TKLlable * placeLab;

@end
static TKLTextViewAlertView *alertView = nil;



@implementation TKLTextViewAlertView

+(instancetype)alterViewWithtitle:(NSString * )titleStr withFrame:(CGRect)fram{
    
    
    if (alertView == nil) {
        alertView = [[TKLTextViewAlertView alloc]initWithFrame:fram];
        alertView.backgroundColor = Wcolor;
        alertView.layer.masksToBounds = YES;
        alertView.layer.cornerRadius = 10;
    }
    
    alertView.titLab = [TKLlable labelWithFrame:CGRectMake(0, 10, fram.size.width, 20) text:titleStr textColor:Bcolor font:Font_6(14) textAlignment:Textcenter backgroundColor:Ccolor];
   
    [alertView addSubview:alertView.titLab];
    
    alertView.textView= [[UITextView alloc] initWithFrame:CGRectMake(10,35, fram.size.width-20,200)];
    alertView.textView.delegate=alertView;
    
    
    [alertView addSubview:alertView.textView];
    alertView.textView.layer.borderColor = JhColor(225, 225, 225).CGColor;
    alertView.textView.layer.borderWidth = 1;
    alertView.placeLab = [TKLlable labelWithFrame:CGRectMake(5, 5, kWidth-50,20) text:@"请输入注销原因，必填，限制50字" textColor:JhColor(204, 204, 204) font:Font_6(12) textAlignment:Textleft backgroundColor:Ccolor];
    
    [alertView.textView addSubview: alertView.placeLab];
//    self.placeholderLabel= [[UILabelalloc]initWithFrame:CGRectMake(3,3,200,20)];self.placeholderLabel.enabled=NO;self.placeholderLabel.text= @"请输入您宝贵的意见或是建议";self.placeholderLabel.font=  [UIFontsystemFontOfSize:15];self.placeholderLabel.textColor= [UIColorlightGrayColor];
//        [self.textViewaddSubview:self.placeholderLabel];

    
    alertView.cancleBtn = [UIButton createBtnFrame:CGRectMake(10, CGRectGetMaxY(alertView.textView.frame)+10, (fram.size.width-40)/2, 40) title:@"取消" bgImageName:@"" textcolor:JhColor(102, 102, 102) laycolor:JhColor(102, 102, 102) action:^(UIButton *button) {
        if ([alertView.delegate respondsToSelector:@selector(textViewCancel)]) {
            [alertView.delegate textViewCancel];
        }
    }];
    alertView.cancleBtn.layer.masksToBounds = YES;
    alertView.cancleBtn.layer.cornerRadius = 20;
    alertView.sureBtn =[UIButton createBtnFrame:CGRectMake(CGRectGetMaxX(alertView.cancleBtn.frame)+20, CGRectGetMaxY(alertView.textView.frame)+10, (fram.size.width-40)/2, 40) title:@"确定" bgImageName:@"" action:^(UIButton *button) {
        
        if ([alertView.delegate respondsToSelector:@selector(textViewStr:)]) {
            [alertView.delegate textViewStr:alertView.textView.text];
        }
        
        
        
        
    }];
    alertView.sureBtn.backgroundColor  = JhColor(102, 102, 102);
    [alertView addSubview:alertView.cancleBtn];
    [alertView addSubview:alertView.sureBtn];
    alertView.sureBtn.layer.masksToBounds = YES;
    alertView.sureBtn.layer.cornerRadius = 20;
    
    
    return alertView;
}

- (void)textViewDidChange:(UITextView*)textView{
    if(alertView.textView.text.length ==0) {
    [alertView.placeLab setHidden:NO];
    
}else{
    if (alertView.textView.text.length >50) {
        alertView.textView.text = [alertView.textView.text substringToIndex:50];
    }
    
    
    [alertView.placeLab setHidden:YES];
    
    }
//    self.automaticallyAdjustsScrollViewInsets=NO;
    
    
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
